'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 副本记录
 * @author sundbcn@gmail.com (sun debing)
 */

var _ = require('lodash');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var copyRecordSchema = require('../schemas/copyRecordSchema');
var CopyRecord = mongoConnector().model('CopyRecord');
var dataApi = require('../libs/dataApi');

var copyRecordModel = module.exports;

/**
 * 添加一个战斗记录
 */
copyRecordModel.addRecord = function (atk_role_id, job_type, copy_id, atk, def, cb) {
    // 创建成功后
    function afterCreate(err, model) {
        if (!!err) {
            console.error(err);
            return cb(err);
        }
        cb(err, model);
    }

    CopyRecord.create({
        atk_role_id: atk_role_id,
        copy_id: copy_id,
        atk: atk,
        def: def
    }, afterCreate);
};

/**
 * 获取一个战斗记录
 */
copyRecordModel.getRecordByAtkRoleId = function (atk_role_id, record_id, cb) {
    CopyRecord.findById(record_id, function (err, copy_record_model) {
        if (!!copy_record_model && copy_record_model.getAtkRoleId() != atk_role_id) {
            cb(new Error('copy record not found'));
        } else {
            cb(null, copy_record_model);
        }
    });
};
